package com.gexiaobao.pigeon.ui.fragment.mine.training

import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.location.LocationManager
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import androidx.core.content.ContextCompat
import com.amap.api.location.AMapLocation
import com.amap.api.location.AMapLocationClient
import com.amap.api.location.AMapLocationClientOption
import com.amap.api.location.AMapLocationListener
import com.amap.api.services.core.LatLonPoint
import com.amap.api.services.geocoder.GeocodeResult
import com.amap.api.services.geocoder.GeocodeSearch
import com.amap.api.services.geocoder.RegeocodeQuery
import com.amap.api.services.geocoder.RegeocodeResult
import com.amap.api.services.weather.LocalWeatherForecastResult
import com.amap.api.services.weather.LocalWeatherLive
import com.amap.api.services.weather.LocalWeatherLiveResult
import com.amap.api.services.weather.WeatherSearch
import com.amap.api.services.weather.WeatherSearchQuery
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.App
import com.gexiaobao.pigeon.app.base.BaseFragment
import com.gexiaobao.pigeon.app.eventViewModel
import com.gexiaobao.pigeon.app.ext.Constant
import com.gexiaobao.pigeon.app.ext.init
import com.gexiaobao.pigeon.app.ext.showMessage
import com.gexiaobao.pigeon.app.model.param.StartTrainingParams
import com.gexiaobao.pigeon.app.util.RxToast
import com.gexiaobao.pigeon.app.util.SettingUtil
import com.gexiaobao.pigeon.app.util.Util
import com.gexiaobao.pigeon.databinding.FragmentTrainingBaseInfoBinding
import com.gexiaobao.pigeon.permissions.PermissionInterceptor
import com.gexiaobao.pigeon.ui.dialog.AlertDialog
import com.gexiaobao.pigeon.ui.dialog.RxDialogDefault
import com.gexiaobao.pigeon.ui.dialog.RxDialogSingle
import com.gexiaobao.pigeon.viewmodel.MyTrainingViewModel
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions
import me.hgj.jetpackmvvm.ext.nav
import me.hgj.jetpackmvvm.ext.navigateAction
import me.hgj.jetpackmvvm.ext.parseState
import me.hgj.jetpackmvvm.ext.util.setOnclickNoRepeat
import java.text.SimpleDateFormat
import java.util.Date

/**
 * @Author      : hxw
 * @Date        : 2023/5/31 18:07
 * @Describe    : LocationListener
 */
class FragmentTrainingInfo : BaseFragment<MyTrainingViewModel, FragmentTrainingBaseInfoBinding>(), GeocodeSearch.OnGeocodeSearchListener,
    AMapLocationListener, WeatherSearch.OnWeatherSearchListener {

    //鸽舍经纬度
    private var mHomingLon: String = ""
    private var mHomingLat: String = ""

    private lateinit var cancelDialog: AlertDialog
    private var isMineCancelFlag = 0

    //获取位置服务
    private lateinit var locationManager: LocationManager

    //高德地图定位相关
    private lateinit var mLocationClient: AMapLocationClient
    private lateinit var mLocationOption: AMapLocationClientOption

    //定位结果
    private lateinit var mapLocation: AMapLocation

    //城市查询
    lateinit var geocoderSearch: GeocodeSearch

    //城市查询
    lateinit var regeocodeResult: RegeocodeResult

    //查询实时天气相关
    private lateinit var weatherlive: LocalWeatherLive
    private lateinit var weatherSearchQuery: WeatherSearchQuery
    private lateinit var weatherSearch: WeatherSearch
//    private var weather = ""
//    private var windDirection = ""
//    private var windPower = ""

    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.viewmodel = mViewModel
        // 获取当前位置管理器
        locationManager = context?.getSystemService(Context.LOCATION_SERVICE) as LocationManager

        //隐私合规检查
        AMapLocationClient.updatePrivacyShow(context, true, true)
        AMapLocationClient.updatePrivacyAgree(context, true)
        weatherlive = LocalWeatherLive()

        eventViewModel.trainingBaseInfoResult.observeInFragment(this) {
            mViewModel.rightTrainingType.set(getString(R.string.homing) + it.homingTotal + "/" + it.liberateTotal)
        }
    }


    @SuppressLint("UseCompatLoadingForDrawables")
    override fun initData() {
        super.initData()

        cancelDialog = context?.let {
            AlertDialog(it).builder()
                .setMsg(getString(R.string.train_fly_detail_detail_fragment_gpsing_go_out_area))
                .setCancelable(false)
                .setNegativeButton(getString(R.string.train_fly_detail_detail_fragment_cancel_gps)) {
                    isMineCancelFlag -= 1
                }
        }!!

        mViewModel.rightTrainingType.set(getString(R.string.fragment_mine_train_fly_detail_under_btn_back_home_percent))
        upDateBottomUI(mTrainingStatus)

        mDatabind.swipeRefreshLayout.init {
            if (mTrainingStatus == 1) {
                mViewModel.getTrainingInfo(mTrainingId.toString())
            } else {
                mViewModel.getTraining(mTrainingId.toString())
            }
        }
    }

    override fun lazyLoadData() {
        super.lazyLoadData()
        if (mTrainingStatus == 1) {
            mViewModel.getTrainingInfo(mTrainingId.toString())
        } else {
            mViewModel.getTraining(mTrainingId.toString())
        }
    }

    override fun onBindViewClick() {
        super.onBindViewClick()
        setOnclickNoRepeat(mDatabind.tvTrainBaseInfoStartFly) {
            when (it) {
                mDatabind.tvTrainBaseInfoStartFly -> {
                    when (mTrainingStatus) {
                        1 -> {//未开始
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                val gpsOk =
                                    (context?.getSystemService(Context.LOCATION_SERVICE) as LocationManager).isProviderEnabled(
                                        LocationManager.GPS_PROVIDER
                                    )
                                if (gpsOk) {
                                    if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.ACCESS_FINE_LOCATION)
                                        != PackageManager.PERMISSION_GRANTED
                                    ) {
                                        // 没有权限，申请权限。
                                        XXPermissions.with(this)
                                            .permission(Permission.ACCESS_COARSE_LOCATION)
                                            .permission(Permission.ACCESS_FINE_LOCATION)
                                            .interceptor(PermissionInterceptor())
                                            .request { _, allGranted ->
                                                if (!allGranted) {
                                                    RxToast.showToast(getString(R.string.Denying_this_permission_location_fail))
                                                }
                                            }
                                    }
                                } else {
                                    AlertDialog(requireContext()).builder()
                                        .setMsg(getString(R.string.train_fly_detail_detail_fragment_start_gps_not_open_alert_msg))
                                        .setNegativeButton(getString(R.string.train_fly_detail_detail_fragment_go_to_open_gps)) {
                                            val intent = Intent()
                                            intent.action = Settings.ACTION_LOCATION_SOURCE_SETTINGS
                                            startActivityForResult(intent, Constant.GPS_REQUEST_CODE)
                                        }.setPositiveButton(getString(R.string.train_fly_detail_detail_fragment_open_gps_later_on)) {
                                            nav().navigateUp()
                                        }.setCancelable(false).show()
                                }
                            }
                            cancelDialog.show()
                            location(AMapLocationClientOption.AMapLocationMode.Device_Sensors)
                        }

                        2 -> {//已开始
                            showStopTrainingDialog()
                        }
                    }
                }
            }
        }
    }

    private fun showStopTrainingDialog() {
        val dialog = RxDialogDefault(context)
        dialog.setTitle(getString(R.string.is_close_training))
        dialog.setSureListener {
            dialog.dismiss()
            showLoading(getString(R.string.loading))
            mViewModel.stopTraining(mTrainingId.toString())
        }
        dialog.setFullScreenWidth()
        dialog.show()
    }

    @SuppressLint("SimpleDateFormat")
    private fun location(locationMode: AMapLocationClientOption.AMapLocationMode) {
        //初始化定位
        mLocationClient = AMapLocationClient(App.instance)
        //设置定位回调监听
        if (locationMode == AMapLocationClientOption.AMapLocationMode.Device_Sensors) {

            isMineCancelFlag += 1
            mLocationClient.setLocationListener { aMapLocation: AMapLocation? ->
                if (isMineCancelFlag != 1) return@setLocationListener
                if (aMapLocation != null) {
                    if (aMapLocation.errorCode == 0) {
                        mapLocation = aMapLocation
                        //定位成功回调信息，设置相关消息
                        aMapLocation.locationType//获取当前定位结果来源，如网络定位结果，详见官方定位类型表
                        val la = aMapLocation.latitude//获取纬度
                        val lo = aMapLocation.longitude//获取经度
                        aMapLocation.accuracy//获取精度信息
                        val df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                        val date = Date(aMapLocation.time)
                        df.format(date)//定位时间

                        geocoderSearch = GeocodeSearch(context)
                        geocoderSearch.setOnGeocodeSearchListener(this)
                        val query = RegeocodeQuery(LatLonPoint(la, lo), 200.0F, GeocodeSearch.AMAP)
                        geocoderSearch.getFromLocationAsyn(query)

                    } else {
                        if (aMapLocation.errorCode == 14) {
                            context?.let {
                                AlertDialog(it).builder().setMsg(getString(R.string.train_fly_detail_detail_fragment_alert_gps_low_msg))
                                    .setNegativeButton(getString(R.string.train_fly_detail_detail_fragment_alert_gps_low_turn_net)) {
                                        showLoading(getString(R.string.train_fly_detail_detail_fragment_alert_gps_low_show_loading_dialog_msg))
                                        location(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy)
                                    }.setPositiveButton(getString(R.string.train_fly_detail_detail_fragment_alert_gps_low_turn_cancel)) {}
                                    .setCancelable(false).show()
                            }
                            if (cancelDialog.dialog!!.isShowing) cancelDialog.dialog!!.dismiss()
                        } else {
                            alertAndDismissDialog("${aMapLocation.errorCode}:" + getString(R.string.train_fly_detail_detail_fragment_alert_gps_err_walk_out_retry))

                        }
                    }
                } else {
                    alertAndDismissDialog(getString(R.string.train_fly_detail_detail_fragment_alert_gps_err_walk_out_retry))
                }
                isMineCancelFlag -= 1

            }
        } else {
            mLocationClient.setLocationListener(this)
        }
        //初始化定位参数
        mLocationOption = AMapLocationClientOption()
        //设置定位模式为Hight_Accuracy高精度模式，Battery_Saving为低功耗模式，Device_Sensors是仅设备模式
//        mLocationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy
        mLocationOption.locationMode = locationMode
        //设置是否返回地址信息（默认返回地址信息）
        mLocationOption.isNeedAddress = true
        //设置是否强制刷新WIFI，默认为强制刷新
        mLocationOption.isWifiActiveScan = true
        //设置是否允许模拟位置,默认为false，不允许模拟位置
        mLocationOption.isMockEnable = true
        //设置定位间隔,单位毫秒,默认为2000ms
        mLocationOption.interval = 2000
        //设置是否只定位一次,默认为false
        mLocationOption.isOnceLocation = true

        //获取最近3s内精度最高的一次定位结果：
//      设置setOnceLocationLatest(boolean b)接口为true，启动定位时SDK会返回最近3s内精度最高的一次定位结果。如果设置其为true，setOnceLocation(boolean b)接口也会被设置为true，反之不会，默认为false。
        mLocationOption.isOnceLocationLatest = true
//      关闭缓存机制
//        mLocationOption.setLocationCacheEnable(false).
        //单位是毫秒，默认30000毫秒，建议超时时间不要低于8000毫秒。
        mLocationOption.httpTimeOut = 10000
        mLocationOption.gpsFirstTimeout = 10000
        //给定位客户端对象设置定位参数
        mLocationClient.setLocationOption(mLocationOption)
        //启动定位
        mLocationClient.startLocation()
    }

    private fun alertAndDismissDialog(msg: String) {
        context?.let {
            AlertDialog(it).builder().setMsg(msg)
                .setNegativeButton(getString(R.string.ok)) {}.setCancelable(false).show()
        }
        if (cancelDialog.dialog?.isShowing == true) cancelDialog.dialog!!.dismiss()
//        showLoadingComplete()
    }

    @SuppressLint("UseCompatLoadingForDrawables")
    override fun createObserver() {
        super.createObserver()
        mViewModel.trainingInfo.observe(viewLifecycleOwner) { resultState ->
            cancelDialog()
            parseState(resultState, {
                mHomingLon = it.homingLon
                mHomingLat = it.homingLat
                mViewModel.pigeonHouseLon.set(SettingUtil.convertToLon(it.homingLon.toDouble()))
                mViewModel.pigeonHouseLat.set(SettingUtil.convertToLat(it.homingLat.toDouble()))
                mTrainingStatus = it.trainingStatus
                mViewModel.rightTrainingType.set(getString(R.string.homing) + it.homingTotal + "/" + it.liberateTotal)
                upDateBottomUI(mTrainingStatus)
            }, {
                showEmptyDialog(it.msg)
            })
        }

        mViewModel.training.observe(viewLifecycleOwner) { resultState ->
            cancelDialog()
            parseState(resultState, {
                mTrainingStatus = it.trainingStatus
                mViewModel.pigeonHouseLon.set(it.homingLon)
                mViewModel.pigeonHouseLat.set(it.homingLat)
                mViewModel.trainingAddress.set(it.trainingAddr)
                mViewModel.trainingTime.set(it.liberateTime)
                mViewModel.trainingLon.set(it.liberateLon)
                mViewModel.trainingLat.set(it.liberateLat)
                mViewModel.trainingDistance.set("${Util.distanceMath("" + it.planedDistance)}" + getString(R.string.kilometre))
                mViewModel.trainingWeather.set(it.weather)
                mViewModel.trainingWindDirection.set(it.windDirection)
                mViewModel.trainingWindPower.set(it.windPower)

                mViewModel.trainingPigeonNo.set(it.liberateTotal.toString() + getString(R.string.yu))
                mViewModel.trainingGuiPigeonNo.set(it.homingTotal.toString() + getString(R.string.yu))
                mViewModel.rightTrainingType.set(getString(R.string.homing) + it.homingTotal + "/" + it.liberateTotal)
                upDateBottomUI(mTrainingStatus)
            }, {
                RxToast.showToast(it.msg)
            })
        }

        mViewModel.startTrainingResult.observe(viewLifecycleOwner) {
            dismissLoading()
            if (it.isSuccess) {
                eventViewModel.toRefreshList.value = true
                if (mTrainingType == 1) {
                    alertSingleFly()
                }
                mViewModel.getTraining(mTrainingId.toString())
            } else {
                RxToast.showToast(it.errorMsg)
            }
        }

        mViewModel.stopTraining.observe(viewLifecycleOwner) {
            dismissLoading()
            if (it.isSuccess) {
                eventViewModel.toRefreshList.value = true
                showLoading(getString(R.string.loading))
                mViewModel.getTraining(mTrainingId.toString())
                eventViewModel.stopTrainingSuccess.value = true
            } else {
                RxToast.showToast(it.errorMsg)
            }
        }
    }

    private fun cancelDialog() {
        if (mDatabind.swipeRefreshLayout.isRefreshing) {
            mDatabind.swipeRefreshLayout.isRefreshing = false
        }
    }

    private fun showEmptyDialog(errorMsg: String) {
        val dialog = RxDialogSingle(context)
        dialog.setTitle(errorMsg)
        dialog.setSureListener {
            dialog.dismiss()
            eventViewModel.getLonLatFailed.value = true
        }
        dialog.setCancelable(false)
        dialog.setCanceledOnTouchOutside(false)
        dialog.setFullScreenWidth()
        dialog.show()
    }

    @SuppressLint("UseCompatLoadingForDrawables")
    private fun upDateBottomUI(mTrainingStatus: Int) {
        when (mTrainingStatus) {
            1 -> {//未开始
                mViewModel.leftTrainingType.set(getString(R.string.train_fly_detail_detail_fragment_not_start))
                mViewModel.trainingType.set(getString(R.string.train_fly_detail_detail_fragment_start_traing))
                mDatabind.tvTrainBaseInfoStartFly.background = resources.getDrawable(R.drawable.round_btn_blue30_b_g, null)
            }

            2 -> {//进行中
                mViewModel.leftTrainingType.set(getString(R.string.train_fly_detail_detail_fragment_not_started))
                mViewModel.trainingType.set(getString(R.string.train_fly_detail_detail_fragment_training_over))
                mDatabind.tvTrainBaseInfoStartFly.background = resources.getDrawable(R.drawable.round_btn_half_right_bg_yellow25, null)
            }

            3 -> {//已结束
                mViewModel.leftTrainingType.set(getString(R.string.finished))
                mViewModel.trainingType.set(getString(R.string.train_fly_detail_detail_fragment_training_is_over))
                mDatabind.tvTrainBaseInfoStartFly.background = resources.getDrawable(R.drawable.round_btn_gray25_b_g, null)
            }

            else -> {
                mViewModel.leftTrainingType.set(getString(R.string.item_train_fly_main_list_not_start))
                mViewModel.trainingType.set(getString(R.string.train_fly_detail_detail_fragment_start_traing))
                mDatabind.tvTrainBaseInfoStartFly.background = resources.getDrawable(R.drawable.round_btn_blue30_b_g, null)
            }
        }
    }

    private fun alertSingleFly() {
        eventViewModel.singleTrainingSuccess.value = true
        val dialog = RxDialogDefault(context)
        dialog.setLeftBtnContent(getString(R.string.talk_to_you_later))
        dialog.setRightBtnContent(getString(R.string.now_intent))
        dialog.setTitle(getString(R.string.click_training_btn_and_fly))
        dialog.setSureListener {
            nav().navigateAction(R.id.action_to_single_training, Bundle().apply {
                putString("trainingId", mTrainingId.toString())
            })
            dialog.dismiss()
        }
        dialog.setCancelListener {
            dialog.dismiss()
        }
        dialog.setFullScreenWidth()
        dialog.show()
    }

    companion object {
        private var mTrainingId: Int = 0
        private var mTrainingType: Int = -1//1、单只训放。2、普通训放
        private var mIntentType = -1//1：列表进入。2：添加进入
        private var mTrainingStatus: Int = -1//1 未开始，2 已开始，3 已结束
        fun newInstance(id: Int, trainingStatus: Int, trainingType: Int, intentType: Int): FragmentTrainingInfo {
            mTrainingId = id
            mTrainingStatus = trainingStatus
            mTrainingType = trainingType
            mIntentType = intentType
            val fragment = FragmentTrainingInfo()
            val bundle = Bundle()
            fragment.arguments = bundle
            return fragment
        }
    }

    private fun requestStartTraining(weatherlive: LocalWeatherLive) {
        if (cancelDialog.dialog?.isShowing == true) cancelDialog.dialog?.dismiss()
        when {
            mViewModel.pigeonHouseLon.get().isEmpty() -> showMessage(getString(R.string.lng_empty_no_fly))
            mViewModel.pigeonHouseLat.get().isEmpty() -> showMessage(getString(R.string.lng_empty_no_fly))
            else -> {
                showLoading(getString(R.string.loading))
                val bodyParam = StartTrainingParams(
                    trainingAddr = regeocodeResult.regeocodeAddress.formatAddress,
                    liberateLon = mapLocation.longitude.toString().trimIndent(),
                    liberateLat = mapLocation.latitude.toString().trimIndent(),
                    weather = weatherlive.weather,
                    windDirection = weatherlive.windDirection,
                    windPower = weatherlive.windPower,
                    trainingId = mTrainingId,
                )
                mViewModel.startTraining(bodyParam)
            }
        }
    }

    @Deprecated("Deprecated in Java")
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == Constant.GPS_REQUEST_CODE) {
            val gpsOk = (context?.getSystemService(Context.LOCATION_SERVICE) as LocationManager).isProviderEnabled(
                LocationManager.GPS_PROVIDER
            )
            if (gpsOk) {
                RxToast.showToast(getString(R.string.train_fly_detail_detail_fragment_go_to_start_gps1_open_success))
            } else {
                context?.let {
                    AlertDialog(it).builder().setMsg(getString(R.string.train_fly_detail_detail_fragment_gps_not_start_cannot_start_training))
                        .setNegativeButton(getString(R.string.train_fly_detail_detail_fragment_go_to_open_gps)) {
                            val intent = Intent()
                            intent.action = Settings.ACTION_LOCATION_SOURCE_SETTINGS
                            startActivityForResult(intent, Constant.GPS_REQUEST_CODE)
                        }.setPositiveButton(getString(R.string.train_fly_detail_detail_fragment_go_to_start_gps1_later_on)) {
                            if (activity != null) requireActivity().finish()
                        }.setCancelable(false).show()
                }
            }
        }
    }

    //天气查询
    private fun queryWeather(city: String) {
        weatherSearchQuery = WeatherSearchQuery(city, WeatherSearchQuery.WEATHER_TYPE_LIVE)
        weatherSearch = WeatherSearch(context)
        weatherSearch.setOnWeatherSearchListener(this)
        weatherSearch.query = weatherSearchQuery
        weatherSearch.searchWeatherAsyn()
    }

    //物理地址逆位回调
    override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) {
        if (rCode == 1000 && result != null) {
            regeocodeResult = result
            queryWeather(result.regeocodeAddress.city)
        } else {
            alertAndDismissDialog(getString(R.string.train_fly_detail_detail_fragment_location_city_err))
        }
    }

    override fun onGeocodeSearched(p0: GeocodeResult?, p1: Int) {
        TODO("Not yet implemented")
    }

    @SuppressLint("SimpleDateFormat")
    override fun onLocationChanged(aMapLocation: AMapLocation?) {
        if (aMapLocation != null) {
            if (aMapLocation.errorCode == 0) {
                mapLocation = aMapLocation
                //定位成功回调信息，设置相关消息
                aMapLocation.locationType//获取当前定位结果来源，如网络定位结果，详见官方定位类型表
                val la = aMapLocation.latitude//获取纬度
                val lo = aMapLocation.longitude//获取经度
                aMapLocation.accuracy//获取精度信息
                val df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                val date = Date(aMapLocation.time)
                df.format(date);//定位时间

                geocoderSearch = GeocodeSearch(context)
                geocoderSearch.setOnGeocodeSearchListener(this)
                val query = RegeocodeQuery(LatLonPoint(la, lo), 200.0F, GeocodeSearch.AMAP)
                geocoderSearch.getFromLocationAsyn(query)
            } else {
                if (aMapLocation.errorCode == 14) {
                    context?.let {
                        AlertDialog(it).builder().setMsg(getString(R.string.train_fly_detail_detail_fragment_alert_gps_low_msg))
                            .setNegativeButton(getString(R.string.train_fly_detail_detail_fragment_alert_gps_low_turn_net)) {
                                showLoading(getString(R.string.train_fly_detail_detail_fragment_alert_gps_low_show_loading_dialog_msg))
                                location(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy)
                            }.setPositiveButton(getString(R.string.train_fly_detail_detail_fragment_alert_gps_low_turn_cancel), {})
                            .setCancelable(false).show()
                    }
//                    showLoadingComplete()
                } else {
                    alertAndDismissDialog("${aMapLocation.errorCode}:" + getString(R.string.train_fly_detail_detail_fragment_alert_gps_err_walk_out_retry))
                }
            }
        } else {
            alertAndDismissDialog(getString(R.string.train_fly_detail_detail_fragment_alert_gps_err_walk_out_retry))
        }
    }

    override fun onWeatherLiveSearched(weatherLiveResult: LocalWeatherLiveResult?, rCode: Int) {
        if (rCode == 1000) {
            if (weatherLiveResult?.liveResult != null) {
                weatherlive = weatherLiveResult.liveResult
                val buffer = StringBuffer()
                buffer.append(
                    weatherlive.reportTime + "发布 " + " ===\n " +
                            weatherlive.weather + " === " +
                            weatherlive.temperature + "°" + " === " +
                            weatherlive.windDirection + "风向  " + " === " +
                            weatherlive.windPower + "级" + " === " +
                            "湿度 :" + weatherlive.humidity + "%"
                )
                requestStartTraining(weatherlive)
            } else {
                alertAndDismissDialog(getString(R.string.train_fly_detail_detail_fragment_weather_err_go_out_retry))
            }
        } else {
            alertAndDismissDialog("$rCode:" + getString(R.string.train_fly_detail_detail_fragment_weather_err_go_out_retry))
        }
    }

    override fun onWeatherForecastSearched(p0: LocalWeatherForecastResult?, p1: Int) {

    }
}